 
 
 
(1)	AllHead.h
#pragma once
 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#define BUFFSIZE 50
 
typedef struct _RoomInfo	//客房信息
{
	char roomType[BUFFSIZE];	//房间类型(标间,大床房,家庭房等)
	float roomPrice;	//房间价格
	float roomCash;		//房间押金
	struct _RoomInfo *next;	//指向下一个节点
}RoomInfo;
 
typedef struct _DinningInfo	//餐饮标准
{
	int dinningPrice;	//餐饮标准
	char dinnName[BUFFSIZE];	//餐饮内容
	struct _DinningInfo *next;	//指向下一个节点
}DinningInfo;
 
typedef struct _OrderInfo
{
	char roomNum[BUFFSIZE];	//入住房号,唯一值
	int roomTypeIndex;	//房间类型索引(标间,大床房,家庭房等)
	int dinningPrice;	//餐饮标准
	char userName[BUFFSIZE];	//住客姓名
	int codeIndex;		//证件类型,身份证,护照等
	char userCode[BUFFSIZE];	//住客证件号
	char userPhone[BUFFSIZE];	//住客电话
	float roomCash;		//已交押金
	char hotelDate[BUFFSIZE];	//入住日期
	int days;	//入住天数
	char closDate[BUFFSIZE];	//结算日期
	float sumMoney;	//消费总额
	struct _OrderInfo *next;	//指向下一个节点
}OrderInfo;
 
(2)	DinningInfo.h
#pragma once
 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#define BUFFSIZE 50
 
typedef struct _RoomInfo	//客房信息
{
	char roomType[BUFFSIZE];	//房间类型(标间,大床房,家庭房等)
	float roomPrice;	//房间价格
	float roomCash;		//房间押金
	struct _RoomInfo *next;	//指向下一个节点
}RoomInfo;
 
typedef struct _DinningInfo	//餐饮标准
{
	int dinningPrice;	//餐饮标准
	char dinnName[BUFFSIZE];	//餐饮内容
	struct _DinningInfo *next;	//指向下一个节点
}DinningInfo;
 
typedef struct _OrderInfo
{
	char roomNum[BUFFSIZE];	//入住房号,唯一值
	int roomTypeIndex;	//房间类型索引(标间,大床房,家庭房等)
	int dinningPrice;	//餐饮标准
	char userName[BUFFSIZE];	//住客姓名
	int codeIndex;		//证件类型,身份证,护照等
	char userCode[BUFFSIZE];	//住客证件号
	char userPhone[BUFFSIZE];	//住客电话
	float roomCash;		//已交押金
	char hotelDate[BUFFSIZE];	//入住日期
	int days;	//入住天数
	char closDate[BUFFSIZE];	//结算日期
	float sumMoney;	//消费总额
	struct _OrderInfo *next;	//指向下一个节点
}OrderInfo;
(3)	OrderInfo.h
#ifndef ORDERINFO_H
#define ORDERINFO_H
 
#include "Allhead.h"
#include "RoomInfo.h"
#include "DinningInfo.h"
 
void orderMainMenu();	//操作菜单
int addOrderInfo(OrderInfo **head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//添加订房信息
int delOrderInfoBySignle(OrderInfo **head);	//删除订房信息(单个删除,主键删除)
int resetOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//修改订房信息
int searchOrderInfoByKey(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//查询订房信息(关键字查询)
int searchOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//查询订房信息(模糊查询)
int lookOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//浏览订房信息
int closOrder(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader);	//结算订单
int readOrderInfoFile(OrderInfo **head);	//从文件中读取数据
int writeOrderInfoFile(OrderInfo *head);	//向文件中写入数据
int printfOrderInfoHeader();	//打印订房头部信息
int printfOrderInfoDataInfo(OrderInfo data, RoomInfo *roomHeader, DinningInfo *dinHeader);	//打印指定订房信息
 
int getOrderInfoLength(OrderInfo *head);	//获取链表长度
int InsertOrderInfoNoHeadList(OrderInfo **head, OrderInfo node);	//尾插法插入链表
int DeleteOrderInfoNoHeadListKey(OrderInfo **head, char *key);	//关键字删除节点
OrderInfo* SearchOrderInfoNoHeadListKey(OrderInfo *head, char *key);	//关键字查询链表
int DestoryOrderInfoNoHeadList(OrderInfo *head);	//销毁查询链表
int orderFunc(OrderInfo *orderHead,RoomInfo *roomHeader,DinningInfo *dinHeader);	//订单主要功能
 
char gCodeType[4][BUFFSIZE] = {"身份证","护照","学生证","军人证"};	//证件类型
int getCodeIndex();	//获取证件索引
int getRoomTypeIndex(RoomInfo *roomHeader);	//获取房型索引
int getDinningIndex(DinningInfo *roomHeader);	//获取餐饮标准索引
 
int orderFunc(OrderInfo *orderHead, RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	int serverNum = 0;	//选择的服务编号
	while (1)
	{
		orderMainMenu();	//打印选项菜单
		scanf("%d", &serverNum);	//选择服务编号
		switch (serverNum)
		{
		case 1:
			addOrderInfo(&orderHead, roomHeader, dinHeader);
			writeOrderInfoFile(orderHead);
			system("pause");
			system("cls");
			break;
		case 2:
			delOrderInfoBySignle(&orderHead);
			writeOrderInfoFile(orderHead);
			system("pause");
			system("cls");
			break;
		case 3:
			resetOrderInfo(orderHead, roomHeader, dinHeader);
			writeOrderInfoFile(orderHead);
			system("pause");
			system("cls");
			break;
		case 4:
			searchOrderInfoByKey(orderHead, roomHeader, dinHeader);
			system("pause");
			system("cls");
			break;
		case 5:
			searchOrderInfo(orderHead, roomHeader, dinHeader);
			system("pause");
			system("cls");
			break;
		case 6:
			lookOrderInfo(orderHead, roomHeader, dinHeader);
			system("pause");
			system("cls");
			break;
		case 7:
			closOrder(orderHead, roomHeader, dinHeader);
			writeOrderInfoFile(orderHead);
			system("pause");
			system("cls");
			break;
		case 0:
			return 1;
		default:
			printf("服务编号有误,请重新选择!\n");
			break;
		}
	}
	system("pause");
	return 1;
}
 
void orderMainMenu()
{
	printf("==================================================\n");
	printf("=============欢迎进入订房管理系统=================\n");
	printf("==================================================\n");
	printf("***** 1.插入订房信息\n");
	printf("***** 2.删除订房信息\n");
	printf("***** 3.修改订房信息\n");
	printf("***** 4.根据关键字查询订房信息\n");
	printf("***** 5.查询订房信息\n");
	printf("***** 6.浏览订房信息\n");
	printf("***** 7.退房结算\n");
	printf("***** 0.返回上一级\n");
	printf("==================================================\n");
	printf("请选择服务编号(0-7):");
}
 
int addOrderInfo(OrderInfo **head ,RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	OrderInfo node;
	OrderInfo *find = NULL;
	printf("请输入入住房号:");	//查找唯一标识在数组中的索引
	scanf("%s", node.roomNum);
	find = SearchOrderInfoNoHeadListKey(*head, node.roomNum);
	if (find != NULL)
	{
		printf("入住房号已被预订,添加失败!\n");
		return 0;
	}
	node.roomTypeIndex = getRoomTypeIndex(roomHeader);
	node.dinningPrice = getDinningIndex(dinHeader);
	printf("请输入住客姓名:");
	scanf("%s", node.userName);
	node.codeIndex = getCodeIndex();
	printf("请输入住客证件号:");
	scanf("%s", node.userCode);
	printf("请输入住客电话:");
	scanf("%s", node.userPhone);
	printf("请输入已交押金:");
	scanf("%f", &node.roomCash);
	printf("请输入入住日期:");
	scanf("%s", node.hotelDate);
	printf("请输入入住天数:");
	scanf("%d", &node.days);
	memcpy(node.closDate, node.hotelDate, strlen(node.hotelDate));
	node.closDate[strlen(node.hotelDate)] = '\0';
	node.sumMoney = 0;
	InsertOrderInfoNoHeadList(head, node);	//尾插法插入链表
	printf("添加订房成功!\n");
	return 1;
}
 
int delOrderInfoBySignle(OrderInfo **head)
{
	OrderInfo node;
	OrderInfo *find = NULL;
	printf("请输入要删除的入住房号:");	//查找唯一标识在数组中的索引
	scanf("%s", node.roomNum);
	find = SearchOrderInfoNoHeadListKey(*head, node.roomNum);
	if (find == NULL)
	{
		printf("入住房号不存在,删除失败!\n");
		return 0;
	}
	DeleteOrderInfoNoHeadListKey(head, node.roomNum);	//关键字删除节点
	printf("删除订房成功!\n");
	return 1;
}
 
int resetOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	OrderInfo node;
	OrderInfo *find = NULL;
	printf("请输入要修改的入住房号:");	//查找唯一标识在数组中的索引
	scanf("%s", node.roomNum);
	find = SearchOrderInfoNoHeadListKey(head, node.roomNum);
	if (find == NULL)
	{
		printf("入住房号不存在,修改失败!\n");
		return 0;
	}
	node.roomTypeIndex = getRoomTypeIndex(roomHeader);
	node.dinningPrice = getDinningIndex(dinHeader);
	printf("请输入住客姓名:");
	scanf("%s", find->userName);
	find->codeIndex = getCodeIndex();
	printf("请输入住客证件号:");
	scanf("%s", find->userCode);
	printf("请输入住客电话:");
	scanf("%s", find->userPhone);
	printf("请输入已交押金:");
	scanf("%f", &find->roomCash);
	printf("请输入入住日期:");
	scanf("%s", find->hotelDate);
	printf("请输入入住天数:");
	scanf("%d", &find->days);
	printf("请输入结算日期:");
	scanf("%s", find->closDate);
	printf("请输入消费总额:");
	scanf("%f", &find->sumMoney);
	printf("修改订房成功!\n");
	return 1;
}
 
int searchOrderInfoByKey(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	OrderInfo node;
	OrderInfo *find = NULL;
	printf("请输入要查询的入住房号:");	//查找唯一标识在数组中的索引
	scanf("%s", node.roomNum);
	find = SearchOrderInfoNoHeadListKey(head, node.roomNum);
	if (find == NULL)
	{
		printf("入住房号不存在,查询失败!\n");
		return 0;
	}
	printfOrderInfoHeader();
	printfOrderInfoDataInfo(*find, roomHeader, dinHeader);
	return 1;
}
 
int searchOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	char buff[BUFFSIZE];
	OrderInfo *p = head;
	printf("请输入要查询的关键字(入住房号,住客姓名,住客证件号,住客电话):");
	scanf("%s", buff);
	printfOrderInfoHeader();
	while (p != NULL)
	{
		if ((strcmp(p->roomNum, buff) == 0) || (strcmp(p->userName, buff) == 0) || \
			(strcmp(p->userCode, buff) == 0) || (strcmp(p->userPhone, buff) == 0))
		{
			printfOrderInfoDataInfo(*p, roomHeader, dinHeader);
		}
		p = p->next;
	}
	return 1;
}
 
int lookOrderInfo(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	OrderInfo *p = head;
	printfOrderInfoHeader();
	while (p != NULL)
	{
		printfOrderInfoDataInfo(*p, roomHeader, dinHeader);
		p = p->next;
	}
	return 1;
}
 
int closOrder(OrderInfo *head, RoomInfo *roomHeader, DinningInfo *dinHeader)	//结算订单
{
	lookOrderInfo(head, roomHeader, dinHeader);
	char roomNum[BUFFSIZE];
	printf("请输入结算房号:");
	scanf("%s", roomNum);
	OrderInfo *find = SearchOrderInfoNoHeadListKey(head, roomNum);
	if (find == NULL)
	{
		printf("没有查询到指定订单,结算失败!");
		return 1;
	}
	if (find->sumMoney > 0)
	{
		printf("订单已结算!\n");
		return 1;
	}
	printf("请输入结算日期:");
	scanf("%s", find->closDate);
	RoomInfo *tempRoom = SearchRoomInfoNoHeadListPos(roomHeader, find->roomTypeIndex);
	DinningInfo *tempDIn = SearchDinningInfoNoHeadListPos(dinHeader, find->dinningPrice);
	float dinTotal = tempDIn->dinningPrice * find->days;	//餐饮费
	float roomTotal = tempRoom->roomPrice *  find->days;	//总房费
	float sumMoney = dinTotal + roomTotal;
	find->sumMoney = sumMoney - find->roomCash;
	printf("餐饮费用:%.2f\n", dinTotal);
	printf("房间费用:%.2f\n", roomTotal);
	printf("总费用:%.2f\n", sumMoney);
	printf("押金:%.2f\n", find->roomCash);
	printf("实际支付费用:%.2f\n", find->sumMoney);
	return 1;
}
 
int readOrderInfoFile(OrderInfo **head)
{
	OrderInfo node = { 0 };
	FILE *file = fopen("OrderInfos.txt", "r");
	if (file == NULL)
	{
		return 0;
	}
	while (fscanf(file, "%s%d%d%s%d%s%s%f%s%d%s%f", node.roomNum, &node.roomTypeIndex, &node.dinningPrice, node.userName, &node.codeIndex, node.userCode, node.userPhone, &node.roomCash, node.hotelDate, &node.days, node.closDate, &node.sumMoney) != EOF)
	{
		InsertOrderInfoNoHeadList(head, node);
	}
	fclose(file);
	return 1;
}
 
int writeOrderInfoFile(OrderInfo *head)
{
	OrderInfo *p = head;
	FILE *file = fopen("OrderInfos.txt", "w");
	if (file == NULL)
	{
		return 0;
	}
	while (p != NULL)
	{
		fprintf(file, "%s %d %d %s %d %s %s %f %s %d %s %f\n", p->roomNum, p->roomTypeIndex, p->dinningPrice, p->userName, p->codeIndex, p->userCode, p->userPhone, p->roomCash, p->hotelDate, p->days, p->closDate, p->sumMoney);
		p = p->next;
	}
	fclose(file);
	return 1;
}
 
int printfOrderInfoHeader()
{
	printf("入住房号:\t");
	printf("房间类型:\t");
	printf("餐饮标准:\t");
	printf("住客姓名:\t");
	printf("证件类型:\t");
	printf("住客证件号:\t");
	printf("住客电话:\t");
	printf("已交押金:\t");
	printf("入住日期:\t");
	printf("入住天数:\t");
	printf("结算日期:\t");
	printf("消费总额:\n");
	return 1;
}
 
int printfOrderInfoDataInfo(OrderInfo data,RoomInfo *roomHeader, DinningInfo *dinHeader)
{
	RoomInfo *tempRoom = SearchRoomInfoNoHeadListPos(roomHeader, data.roomTypeIndex);
	DinningInfo *tempDin = SearchDinningInfoNoHeadListPos(dinHeader, data.dinningPrice);
	printf("%-16s", data.roomNum);
	printf("%-16s", tempRoom->roomType);
	printf("%-16d", tempDin->dinningPrice);
	printf("%-16s", data.userName);
	printf("%-16d", data.codeIndex);
	printf("%-16s", data.userCode);
	printf("%-16s", data.userPhone);
	printf("%-16f", data.roomCash);
	printf("%-16s", data.hotelDate);
	printf("%-16d", data.days);
	if (strcmp(data.hotelDate, data.closDate) == 0)
	{
		printf("%-16s", "");
	}
	else
	{
		printf("%-16s", data.closDate);
	}
	printf("%-16f\n", data.sumMoney);
	return 1;
}
 
int getOrderInfoLength(OrderInfo *head)
{
	int length = 0;
	OrderInfo *p = head;
	while (p != NULL)
	{
		p = p->next;
		length++;
	}
	return length;
}
int InsertOrderInfoNoHeadList(OrderInfo **head, OrderInfo node)
{
	OrderInfo *phead = NULL;	//头指针，上一节点指针，新节点指针
	OrderInfo *pnew = (OrderInfo *)malloc(sizeof(OrderInfo));
	if (pnew == NULL)
	{
		printf("malloc failed!\n");
		return 0;
	}
	phead = (*head);
	memcpy(pnew->roomNum, node.roomNum, strlen(node.roomNum));
	pnew->roomNum[strlen(node.roomNum)] = '\0';
	pnew->roomTypeIndex = node.roomTypeIndex;
	pnew->dinningPrice = node.dinningPrice;
	memcpy(pnew->userName, node.userName, strlen(node.userName));
	pnew->userName[strlen(node.userName)] = '\0';
	pnew->codeIndex = node.codeIndex;
	memcpy(pnew->userCode, node.userCode, strlen(node.userCode));
	pnew->userCode[strlen(node.userCode)] = '\0';
	memcpy(pnew->userPhone, node.userPhone, strlen(node.userPhone));
	pnew->userPhone[strlen(node.userPhone)] = '\0';
	pnew->roomCash = node.roomCash;
	memcpy(pnew->hotelDate, node.hotelDate, strlen(node.hotelDate));
	pnew->hotelDate[strlen(node.hotelDate)] = '\0';
	pnew->days = node.days;
	memcpy(pnew->closDate, node.closDate, strlen(node.closDate));
	pnew->closDate[strlen(node.closDate)] = '\0';
	pnew->sumMoney = node.sumMoney;
	if (phead == NULL)
	{
		phead = pnew;
		pnew->next = NULL;
		(*head) = phead;
		return 1;
	}
	while (phead->next != NULL)
	{
		phead = phead->next;
	}
	phead->next = pnew;
	pnew->next = NULL;
	return 1;
}
 
int DeleteOrderInfoNoHeadListKey(OrderInfo **head, char *key)
{
	int isExist = 0;
	OrderInfo *p = NULL;
	OrderInfo *q = NULL;
	if ((*head) == NULL)
	{
		printf("链表为空!\n");
		return isExist;
	}
	p = (*head);
	q = p->next;
	while (q != NULL)
	{
		if (strcmp(q->roomNum, key) == 0)
		{
			p->next = q->next;
			free(q);
			q = p->next;
			isExist = 1;
		}
		else
		{
			p = p->next;
			q = q->next;
		}
	}
	if ((*head) != NULL && (strcmp((*head)->roomNum, key) == 0))
	{
		q = (*head);
		(*head) = q->next;
		free(q);
		isExist = 1;
		return isExist;
	}
	return isExist;
}
 
OrderInfo* SearchOrderInfoNoHeadListKey(OrderInfo *head, char *key)
{
	OrderInfo *p = head;
	while (p != NULL)
	{
		if (strcmp(p->roomNum, key) == 0)
		{
			return p;
		}
		p = p->next;
	}
	return NULL;
}
 
int DestoryOrderInfoNoHeadList(OrderInfo *head)
{
	OrderInfo *q = head;
	OrderInfo *tmp = NULL;
	head = NULL;
	while (q != NULL)
	{
		tmp = q;
		q = q->next;
		free(tmp);
		tmp = NULL;
	}
	return 1;
}
 
int getCodeIndex() //获取证件索引
{
	int m = 0;
	int index = -1;
	while (1)
	{
		for (m = 0;m < 4;m++)
		{
			printf("%d:%s\n",m+1,gCodeType[m]);
		}
		printf("请选择证件类型(1-4):\n");
		scanf("%d",&index);
		if (index >= 1 && index <= 4)
		{
			return index - 1;
		}
		else
		{
			printf("证件类型错误,请重新选择!\n");
		}
	}
	return index;
}
 
int getRoomTypeIndex(RoomInfo *roomHeader)	//获取房型索引
{
	int index = 0;
	while (1)
	{
		index = selectRoomType(roomHeader);
		if (index == -1)
		{
			printf("房型编号有误,请重新选择!\n");
			continue;
		}
		break;
	}
	return index - 1;
}
 
int getDinningIndex(DinningInfo *roomHeader)	//获取餐饮标准索引
{
	int index = 0;
	while (1)
	{
		index = selectDinningType(roomHeader);
		if (index == -1)
		{
			printf("餐饮标准编号有误,请重新选择!\n");
			continue;
		}
		break;
	}
	return index - 1;
}
 
#endif
(4)	RoomInfo.h
#ifndef ROOMINFO_H
#define ROOMINFO_H
 
#include "Allhead.h"
 
void roomMainMenu();	//操作菜单
int addRoomInfo(RoomInfo **head);	//添加客房信息信息
int resetRoomInfo(RoomInfo *head);	//修改客房信息信息
int lookRoomInfo(RoomInfo *head);	//浏览客房信息信息
int readRoomInfoFile(RoomInfo **head);	//从文件中读取数据
int writeRoomInfoFile(RoomInfo *head);	//向文件中写入数据
int printfRoomInfoHeader();	//打印客房信息头部信息
int printfRoomInfoDataInfo(RoomInfo data);	//打印指定客房信息信息
 
int getRoomInfoLength(RoomInfo *head);	//获取链表长度
int InsertRoomInfoNoHeadList(RoomInfo **head,RoomInfo node);	//尾插法插入链表
int DeleteRoomInfoNoHeadListKey(RoomInfo **head,char *key);	//关键字删除节点
RoomInfo* SearchRoomInfoNoHeadListKey(RoomInfo *head,char *key);	//关键字查询链表
RoomInfo* SearchRoomInfoNoHeadListPos(RoomInfo *head, int pos);	//指定位置查询链表
int DestoryRoomInfoNoHeadList(RoomInfo *head);	//销毁查询链表
 
int selectRoomType(RoomInfo *head);	//显示房间类型
int roomFunc(RoomInfo *head);
 
int roomFunc(RoomInfo *head)
{
	int serverNum = 0;	//选择的服务编号
	while(1)
	{
		roomMainMenu();	//打印选项菜单
		scanf("%d",&serverNum);	//选择服务编号
		switch(serverNum)
		{
		case 1:
			addRoomInfo(&head);
			writeRoomInfoFile(head);
			system("pause");
			system("cls");
			break;
		case 2:
			resetRoomInfo(head);
			writeRoomInfoFile(head);
			system("pause");
			system("cls");
			break;
		case 3:
			lookRoomInfo(head);
			system("pause");
			system("cls");
			break;
		case 0:
			return 1;
		default:
			printf("服务编号有误,请重新选择!\n");
			break;
		}
	}
	system("pause");
	return 1;
}
 
void roomMainMenu()
{
	printf("==================================================\n");
	printf("=============欢迎进入订房管理系统=================\n");
	printf("==================================================\n");
	printf("***** 1.插入客房信息\n");
	printf("***** 2.修改客房信息\n");
	printf("***** 3.浏览客房信息\n");
	printf("***** 0.返回上一级   \n");
	printf("==================================================\n");
	printf("请选择服务编号(0-3):");	
}
 
int addRoomInfo(RoomInfo **head)
{
	RoomInfo node;
	RoomInfo *find = NULL;
	printf("请输入房间类型:");	//查找唯一标识在数组中的索引
	scanf("%s",node.roomType);
	find = SearchRoomInfoNoHeadListKey(*head, node.roomType);
	if(find != NULL)
	{
		printf("房间类型已存在,添加失败!\n");
		return 0;
	}
	printf("请输入房间价格(元/天):");
	scanf("%f",&node.roomPrice);
	printf("请输入房间押金(元):");
	scanf("%f",&node.roomCash);
	InsertRoomInfoNoHeadList(head,node);	//尾插法插入链表
	printf("添加客房信息成功!\n");
	return 1;
}
 
int resetRoomInfo(RoomInfo *head)
{
	RoomInfo node;
	RoomInfo *find = NULL;
	printf("请输入要修改的房间类型:");	//查找唯一标识在数组中的索引
	scanf("%s",node.roomType);
	find = SearchRoomInfoNoHeadListKey(head, node.roomType);
	if(find == NULL)
	{
		printf("房间类型不存在,修改失败!\n");
		return 0;
	}
	printf("请输入房间价格:");
	scanf("%f",&find->roomPrice);
	printf("请输入房间押金:");
	scanf("%f",&find->roomCash);
	printf("修改客房信息成功!\n");
	return 1;
}
 
int lookRoomInfo(RoomInfo *head)
{
	RoomInfo *p = head;
	printfRoomInfoHeader();
	while(p != NULL)
	{
		printfRoomInfoDataInfo(*p);
		p = p->next;
	}
	return 1;
}
 
int readRoomInfoFile(RoomInfo **head)
{
	RoomInfo node = {0};
	FILE *file = fopen("RoomInfos.txt","r");
	if(file == NULL)
	{
		return 0;
	}
	while(fscanf(file,"%s%f%f",node.roomType,&node.roomPrice,&node.roomCash)!=EOF)
	{
		InsertRoomInfoNoHeadList(head,node);
	}
	fclose(file);
	return 1;
}
 
int writeRoomInfoFile(RoomInfo *head)
{
	RoomInfo *p = head;
	FILE *file = fopen("RoomInfos.txt","w");
	if(file == NULL)
	{
		return 0;
	}
	while(p != NULL)
	{
		fprintf(file,"%s %f %f\n",p->roomType,p->roomPrice,p->roomCash);
		p = p->next;
	}
	fclose(file);
	return 1;
}
 
int printfRoomInfoHeader()
{
	printf("房间类型:\t");
	printf("房间价格:\t");
	printf("房间押金:\n");
	return 1;
}
 
int printfRoomInfoDataInfo(RoomInfo data)
{
	printf("%-16s",data.roomType);
	printf("%-16f",data.roomPrice);
	printf("%-16f\n",data.roomCash);
	return 1;
}
 
int getRoomInfoLength(RoomInfo *head)
{
	int length = 0;
	RoomInfo *p = head;
	while (p != NULL)
	{
		p = p->next;
		length++;
	}
	return length;
}
int InsertRoomInfoNoHeadList(RoomInfo **head,RoomInfo node)
{
	RoomInfo *phead = NULL;	//头指针，上一节点指针，新节点指针
	RoomInfo *pnew = (RoomInfo *)malloc(sizeof(RoomInfo));
	if(pnew == NULL)
	{
		printf("malloc failed!\n");
		return 0;
	}
	phead = (*head);
	memcpy(pnew->roomType,node.roomType,strlen(node.roomType));
	pnew->roomType[strlen(node.roomType)] = '\0';
	pnew->roomPrice = node.roomPrice;
	pnew->roomCash = node.roomCash;
	if(phead == NULL)
	{
		phead = pnew;
		pnew->next = NULL;
		(*head) = phead;
		return 1;
	}
	while (phead->next != NULL)
	{
		phead = phead->next;
	}
	phead->next = pnew;
	pnew->next = NULL;
	return 1;
}
 
int DeleteRoomInfoNoHeadListKey(RoomInfo **head,char *key)
{
	int isExist = 0;
	RoomInfo *p = NULL;
	RoomInfo *q = NULL;
	if ((*head) == NULL)
	{
		printf("链表为空!\n");
		return isExist;
	}
	p = (*head);
	q = p->next;
	while (q != NULL)
	{
		if(strcmp(q->roomType,key)==0)
		{
			p->next = q->next;
			free(q);
			q = p->next;
			isExist = 1;
		}
		else
		{
			p = p->next;
			q = q->next;
		}
	}
	if ((*head) != NULL && (strcmp((*head)->roomType,key)==0))
	{
		q = (*head);
		(*head) = q->next;
		free(q);
		isExist = 1;
		return isExist;
	}
	return isExist;
}
 
RoomInfo* SearchRoomInfoNoHeadListKey(RoomInfo *head,char *key)
{
	RoomInfo *p = head;
	while (p != NULL)
	{
		if (strcmp(p->roomType,key)==0)
		{
			return p;
		}
		p = p->next;
	}
	return NULL;
}
 
RoomInfo* SearchRoomInfoNoHeadListPos(RoomInfo *head, int pos)
{
	RoomInfo *p = head;
	int index = 0;
	while (p != NULL)
	{
		if (index == pos)
		{
			return p;
		}
		p = p->next;
		index++;
	}
	return NULL;
}
 
int DestoryRoomInfoNoHeadList(RoomInfo *head)
{
	RoomInfo *q = head;
	RoomInfo *tmp = NULL;
	head = NULL;
	while (q != NULL)
	{
		tmp = q;
		q = q->next;
		free(tmp);
		tmp = NULL;
	}
	return 1;
}
 
int selectRoomType(RoomInfo *head)	//显示房间类型
{
	int roomLength = getRoomInfoLength(head);
	RoomInfo *p = head;
	int count = 1, index = 0;
	while (p != NULL)
	{
		printf("%d:类型:%s 房费:%.2f 押金:%.2f\n", count++, p->roomType, p->roomPrice, p->roomCash);
		p = p->next;
	}
	printf("请选择房型编号(1-%d):", roomLength);
	scanf("%d",&index);
	if (index >= 1 && index <= roomLength)
	{
		return index;
	}
	return -1;
}
 
#endif
(5)	RoomManager.c
#include "RoomInfo.h"
#include "DinningInfo.h"
#include "OrderInfo.h"
 
void mainMenu();
 
int main()
{
	RoomInfo *rooms = NULL;
	DinningInfo *dinnings = NULL;
	OrderInfo *orders = NULL;
	int serverNum = 0;
	readRoomInfoFile(&rooms);
	readDinningInfoFile(&dinnings);
	readOrderInfoFile(&orders);
	int roomSize = 0, dinSize = 0;
	while (1)
	{
		mainMenu();	//打印选项菜单
		scanf("%d", &serverNum);	//选择服务编号
		switch (serverNum)
		{
		case 1:
			roomSize = getRoomInfoLength(rooms);
			dinSize = getDinningInfoLength(dinnings);
			if (roomSize == 0 || dinSize == 0)
			{
				printf("请先录入房间信息与餐饮信息!\n");
				system("pause");
				system("cls");
				break;
			}
			system("cls");
			orderFunc(orders, rooms, dinnings);
			break;
		case 2:
			system("cls");
			roomFunc(rooms);
			break;
		case 3:
			system("cls");
			dinFunc(dinnings);
			break;
		case 0:
			system("pause");
			return 1;
		default:
			printf("服务编号有误,请重新选择!\n");
			break;
		}
	}
	//roomFunc(rooms);
	//dinFunc(dinnings);
	orderFunc(orders, rooms, dinnings);
	system("pause");
	return 0;
}
 
void mainMenu()
{
	printf("==================================================\n");
	printf("=============欢迎进入订房管理系统=================\n");
	printf("==================================================\n");
	printf("***** 1.客房预订\n");
	printf("***** 2.客房管理\n");
	printf("***** 3.餐费管理\n");
	printf("***** 0.退出   \n");
	printf("==================================================\n");
	printf("请选择服务编号(0-3):");
}